/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.model;

import sw6.digipecs.database.SentenceBoardStateCursor;
import sw6.digipecs.exceptions.IDNotFoundException;
import sw6.digipecs.exceptions.ImageIsEmptyException;
import android.content.Context;

public class ExtImageInSentenceBoard extends ExtImage {
	
	private boolean mLocked = false;
	
	public ExtImageInSentenceBoard(Context context) {
		super(context);
	}
	
	public ExtImageInSentenceBoard(Context context, int id) throws IDNotFoundException {
		super(context, id);
	}

	public ExtImageInSentenceBoard(Context context, int id, int index) throws IDNotFoundException {
		super(context, id);
		
		mDB.open();
		
		SentenceBoardStateCursor cursor = mDB.fetchSentenceBoardItem(index);
		if (cursor.moveToFirst()) {
			mLocked = cursor.getSentenceBoardStateLock();
		} else {
			cursor.close();
			mDB.close();
			throw new IDNotFoundException();
		}
		
		cursor.close();
		mDB.close();
	}

	public boolean isLocked() {
		return mLocked;
	}
	
	public void unlock(int pos) throws ImageIsEmptyException {
		mDB.open(); 
		mDB.setLockedSentenceBoardItem(pos, getId(), false);
		mDB.close(); 
	}

}
